home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
DIFIND.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-24
|
6KB
|
179 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: difind.c
// Title: Data File I/O Library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains to locate files based on names. These are basically
// helper routines for the open functions.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <di.h>
//----------------------------------------------------------------------------
// Description: Locate logical file entry.
// Parameters:pcsz Full file name.
// usType File type to open.
// phpf Variable to receive physical file handle
// pcDir Variable to receive offset of directory entry
// pdir Buffer to receive directory entry
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioFindLogical(PCSZ pcsz, USHORT usType, PHPF phpf, PSIZET pcDir, PDATADIR pdir)
{
CHAR szPhysical[MAX_DIO_NAME+1];
CHAR szLogical[MAX_DIO_NAME+1];
if (!DioSplitName(pcsz, szPhysical, szLogical))
return FALSE;
if (szPhysical[0])
{
if (!DioFindPhyiscal(szPhysical, phpf))
return FALSE;
if (!DioFindLogicalSearch(szLogical, usType, *phpf, pcDir, pdir))
return FALSE;
}
Assert(phpf);
for (*phpf = 0; *phpf < MAX_PHYSICAL_FILES; ++(*phpf))
if (di.physical[*phpf].fUsed)
{
if (DioFindLogicalSearch(szLogical, usType, *phpf, pcDir, pdir))
return TRUE;
}
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Search for logical file entry.
// Parameters: szLogical Logical file name
// usType File type to open.
// hpf Physical file handle
// pcDir Variable to receive offset of directory entry
// pdir Buffer to receive directory entry
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioFindLogicalSearch(PCSZ pcszLogical, USHORT usType, HPF hpf, PSIZET pcDir, PDATADIR pdir)
{
DATAHDR hdr;
CHAR szName[DFD_NAME+1];
if (!DioHeaderRead(hpf, &hdr))
return FALSE;
Assert(pcDir && pdir && pcszLogical);
for (*pcDir = 0; *pcDir < (SIZET)hdr.usDirectoryUsed; ++*pcDir)
{
if (!DioDirRead(hpf, *pcDir, pdir))
return FALSE;
memset(szName,0,sizeof(szName));
memcpy(szName, pdir->chName, sizeof(pdir->chName));
if (stricmp(szName, pcszLogical) == 0
&& pdir->usType == usType)
return TRUE;
}
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Find physical file entry by name
// Parameters: pcsz Internal physical file name
// phpf Variable to variable to recieve file handle
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioFindPhyiscal(PCSZ pcsz, PHPF phpf)
{
HPF hpf;
Assert(pcsz);
Assert(pcsz[0] && strlen(pcsz) <= MAX_PHYSICAL_NAME);
Assert(phpf);
for (hpf = 0; hpf < MAX_PHYSICAL_FILES; ++hpf)
if (di.physical[hpf].fUsed
&& stricmp(di.physical[hpf].szName, pcsz) == 0)
{
*phpf = hpf;
return TRUE;
}
Error("Physical file '%s' not found.", pcsz);
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Split a name into the physical and logical file name.
// Parameters: pcsz Full name
// pszPhysical Buffer to receive physical name
// pszLogical Buffer to receive logical name
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E DioSplitName(PCSZ pcsz, PSZ pszPhysical, PSZ pszLogical)
{
PSZ ptr;
Assert(pcsz);
Assert(pcsz[0] && strlen(pcsz) <= MAX_DIO_NAME);
Assert(pszPhysical && pszLogical);
if ((ptr = strchr(pcsz, '~')) != NULL)
{
*ptr = '\0'; // Explicit physical name
Assert(strlen(pcsz) <= MAX_PHYSICAL_NAME);
strcpy(pszPhysical, pcsz);
*ptr = '~';
Assert(strlen(ptr + 1) <= MAX_LOGICAL_NAME);
strcpy(pszLogical, ptr + 1);
}
else
{
pszPhysical[0] = '\0';
Assert(strlen(pcsz) <= MAX_LOGICAL_NAME);
strcpy(pszLogical, pcsz);
}
Assert(pszLogical[0]);
return TRUE;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------